package com.wjy.Data_Structure.sort.sort1;

import java.util.Arrays;

import com.wjy.Data_Structure.sort.DataWrap;

public class SelectSort {
	//直接选择排序
	public static void selectSort(DataWrap[] data) {
		System.out.println("开始排序:");
		int arrayLength = data.length;
		for (int i = 0; i < arrayLength - 1; i++) {
			//保留本趟比较中最小值的s索引
			int minIndex = i;
			for (int j = i + 1; j < arrayLength; j++) {
				if (data[minIndex].compareTo(data[j]) > 0) {
					minIndex = j;
				}
			}
			if (minIndex != i) {
				DataWrap tmp = data[i];
				data[i] = data[minIndex];
				data[minIndex] = tmp;
			}
			System.out.println(Arrays.toString(data));
		}
	}

	public static void main(String[] arys) {
		DataWrap[] data = { new DataWrap(21, ""), new DataWrap(30, ""), new DataWrap(49, ""), new DataWrap(30, ""),
				new DataWrap(16, ""), new DataWrap(9, ""), };
		System.out.println("排序之前：\n" + Arrays.toString(data));
		selectSort(data);
		System.out.println("排序之后：\n" + Arrays.toString(data));
	}

}
